 {include file="public/header" /}
 <style type="text/css">.gray-bg{ background: #fff; }.wrapper{ padding:0px;}.asdh5 h5{border-top: 1px dotted #ccc; padding-top: 20px;margin-top: 20px;}</style>
 <body class="gray-bg">
 <div class="wrapper wrapper-content">
    <div class="row">
        <form class="form-horizontal" method="post">
            <div class="col-sm-12" {php}if(input("id")==1){echo 'style="display:none"';}{/php}>
                <div class="ibox-content asdh5">
                    <h2>标签设置</h2>
                    <div class="form-group">
                        <label class="col-sm-2 control-label"></label>
                        <div class="col-sm-4">
                            <select class="form-control" id="topicselect1">
                            </select>
                        </div>
                        <div class="col-sm-1" style="display: flex;">
                            <span class="btn btn-primary " onclick="addtopic(1)">添加</span>
                        </div>
                        <div class="col-sm-4" style="display: flex;">
                            <input type="text" class="form-control" id="searchtopic1" placeholder="快捷搜索标签">
                            <span class="btn btn-primary " onclick="searchtopic(1)">搜索</span>
                        </div>
                    </div>
                    <div class="wrapper-content" id="wrapper-content">
                        {$labels}
                    </div>
                </div>

            </div>
                    
        </form>
    </div>
</div>
{include file="public/footer" /}
{load href="__PLUGINS__iCheck/icheck.min.js"}
{load href="__PLUGINS__iCheck/custom.css"}
<script type="text/javascript">
$(document).ready(function(){
     $(".i-checks").iCheck({
        checkboxClass: "icheckbox_square-green",
        radioClass: "iradio_square-green",
    })

});
    function searchtopic(key = 1) {
        let keyword = $(`#searchtopic${key}`).val();
        ajaxFun("post","{:url('article/searchtopic')}",{keyword},'json',function(ret){
            if(ret){
                let html = ''
                ret.forEach(item=>{
                    html += `<option value="${item.id}">${item.name}</option>`
                })
                $(`#topicselect${key}`).html(html)
            }else{
                swal_msg("错误",ret,"error");
            }
        })
    }

    function addtopic(key = 1) {
        let name = $(`#topicselect${key}`).find('option:selected').text()
        let select = $(`#topicselect${key}`).val()
        if (!select) return;
        let pause = false
        $(`input[name^="topic${key}"]`).each(function(){
            if (select == $(this).val()) return pause = true;
        }); 
        if (pause) return;
        $(`#wrapper-content`).append(`<div class="col-sm-2"><div class="radio i-checks">
                            <label><input type="checkbox" checked value="${select}" name="data[]">${name}</label>
                        </div></div>`)

        $(".i-checks").iCheck({
            checkboxClass: "icheckbox_square-green",
            radioClass: "iradio_square-green",
        })
    }
</script>
{include file="public/bottom" /}
 
